export interface ITree {
  name: string;
  children?: ITree[];
}

export const traverseTreeByLevel = (tree: ITree, traverse?: (interview: ITree) => any) => {
  const queue: ITree[] = [tree];

  while(queue.length) {
    const interview = queue.shift() as ITree;

    traverse?.(interview);
    interview?.children?.forEach(child => {
      queue.push(child);
    });
  }
};
